package fy.mdm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;

import com.alibaba.fastjson.JSONObject;

import fy.config.FyConfig;
import fy.mdm.bean.NewFinBean;
import fy.util.DBUtil;

public class NewFinDao {
	private final static String SELECTOACS = "select a.plan_id,a.Factory_id,a.Plan_number-a.Taking_number,a.LINE_NUMBER,a.FACTORY,a.PRODUCT_NAME,a.PLAN_DATE,a.PART_NUMBER,a.BOX_IDENTIFIER,a.BUCKLE_NUMBER,a.LIMIT,a.CEILING,a.PROCUREMENT,a.PIECES_NUMBER,b.field0008 请求部门,b.field0009 计划库存组织,b.field0010 包装材质,b.field0011 客户号,b.field0012 客户名称,b.field0013 发运地址,b.field0015 允差下限,b.field0016 允差上限 from OACS a left join formmain_8620 b on a.Plan_id=b.field0007 where Plan_id=?";// 正式formmain_8620
	private String planid;
	private String[] factoryIdArray;
	private static Log log = LogFactory.getLog(NewFinDao.class);
	NewFinBean NewFinBean = new NewFinBean();

	public JSONArray newfindeInfo() throws Exception {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		JSONArray jso = new JSONArray();
		JSONObject jo = new JSONObject();
		try {
			conn = DBUtil.connect(FyConfig.getOA_DB_CONFIG());
			pst = conn.prepareStatement(SELECTOACS);
			pst.setString(1, planid);
			rs = pst.executeQuery();

			while (rs.next()) {
				NewFinBean.setPlanid(rs.getString(1));
				NewFinBean.setFactory_id(rs.getString(2));
				NewFinBean.setPlan_number(rs.getString(3));
				NewFinBean.setLine_Number(rs.getString(4));
				NewFinBean.setFactory(rs.getString(5));
				NewFinBean.setProduct_Name(rs.getString(6));
				NewFinBean.setPlan_Date(rs.getString(7));
				NewFinBean.setPart_number(rs.getString(8));
				NewFinBean.setBox_Identifier(rs.getString(9));
				NewFinBean.setBuckle_number(rs.getString(10));
				NewFinBean.setLimit(rs.getString(11));
				NewFinBean.setCeiling(rs.getString(12));
				NewFinBean.setProcurement(rs.getString(13));
				NewFinBean.setPieces_number(rs.getString(14));
				NewFinBean.setDepartment(rs.getString(15));
				NewFinBean.setPlanned_inventory(rs.getString(16));
				NewFinBean.setPacking_material(rs.getString(17));
				NewFinBean.setCustomer_number(rs.getString(18));
				NewFinBean.setCustomer_name(rs.getString(19));
				NewFinBean.setShipping_address(rs.getString(20));
				NewFinBean.setTolerance_limit(rs.getString(21));
				NewFinBean.setUpper_tolerance(rs.getString(22));
				jso.put(NewFinBean.getJSONObject());
			}

//			System.out.println(jso);
			log.info("结果：" + jso);
		} catch (Exception e) {
//			System.out.println(e);
		} finally {
			DBUtil.close(rs, pst, conn);
		}
		return jso;

	}

	public String getPlanid() {
		return planid;
	}

	public void setPlanid(String planid) {
		this.planid = planid;
	}

	public String[] getFactoryIdArray() {
		return factoryIdArray;
	}

	public void setFactoryIdArray(String[] factoryIdArray) {
		this.factoryIdArray = factoryIdArray;
	}

}
